/*
 * @lc app=leetcode.cn id=238 lang=golang
 *
 * [238] 除自身以外数组的乘积
 */

// @lc code=start
package main

func productExceptSelf(nums []int) []int {
	res := make([]int, len(nums))
	res[0] = 1
	n := len(nums)
	for i := 1; i < n; i++ {
		res[i] = res[i-1] * nums[i-1]
	}
	tmp := 1
	for i := n - 1; i >= 0; i-- {
		// fmt.Println(i)
		res[i] = tmp * res[i]
		tmp *= nums[i]
	}
	return res
}

// @lc code=end
